#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,L,V;
int d[100005];
int v[100005];
int a[100005];
int p[100005];
int c[100005];
int sum;
bool b = true;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    for(int x = 1;x <= T;x ++){
        cin >> n >> m >> L >> V;
        int sum = 0;
        for(int i = 1;i <= n;i ++)
        {
            cin >> d[i] >> v[i] >> a[i];
        }
        for(int i = 1;i <= m;i ++)
        {
            cin >> p[i];
        }
        sort(p + 1,p + m + 1);
        for(int i = 1;i <= n;i ++)
        {
            if(v[i] > V && d[i] <= p[m])
            {
                sum ++;
            }
        }
        for(int i = 1;i <= n;i ++)
        {
            if(a[i] != 0)
            {
                b = false;
                break;
            }
        }
        if(b)
        {
            if(sum == 0)
            {
                cout << sum << " " << m<< endl;
            }
            else{
                cout << sum << " " << m - 1 << endl;
            }
        }
    }
    return 0;
}
